#include<iostream>
#include <string>


int divisorCount(int value) {
    int divisors = 0;
    for (int i = value; i > 0; i--) {
        if (value % i == 0) {
            divisors++;
        }
    }
    return divisors;
}

int main()
{
    int value = 0;
    std::cin >> value;

    std::string str = std::to_string(value);

    if (value < 0) {
        std::cout << 0;
        return 0;
    }
    if (str.size() < 4 || str.size() > 4) {
        std::cout << 0;
        return 0;
    }
    std::string newStr = str;
    int bigValue = 0;
    for (int j = 1; j < 5;j++) {
    for (int i = 0; i < 4; i++) {
        if (i + j > str.size()) {
            continue;
        }
        newStr = str.substr(i, j);
            int newValue = stoi(newStr);
            int valueDivisorCount = divisorCount(newValue);

            if (valueDivisorCount == 2) {
                if (newValue > bigValue)bigValue = newValue;
            }

        }

    }
    std::cout << bigValue;
}